
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react";
//import axios from 'axios';
//import basicurl from '../../basicurl.json';
// let basicurl;
// const getjsondata = async() => {
//     await axios.get("/basicurl.json")
//         .then(json => { basicurl = json.data.basicurl });
//         console.log(basicurl.endsWith('/'));
//     return basicurl;
// }
// async function getDynamicBaseUrl() {
//     const response = await fetch('/basicurl.json');
//     const data = await response.json();
//     console.log(data.basicurl);
//     return data.basicurl;
//   }


//const url='http://192.168.8.104:4000/';
//请求API
export const loginApi = createApi({
    reducerPath: 'loginApi',
    //设置基本请求路径
    baseQuery: fetchBaseQuery({
        baseUrl: window.app
    }),

    endpoints(build) {
        return {

            //登录请求
            postlogin: build.mutation({
                query(data) {
                    return {
                        url: 'Login/Login',
                        method: 'POST',
                        body: data
                    };
                },
                transformResponse(baseQuery) {
                    return baseQuery;

                }
            }),
            //登录请求
            postlogout: build.mutation({
                query(data) {
                    return {
                        url: 'Login/Logout',
                        method: 'POST',
                        body: data
                    };
                },
                transformResponse(baseQuery) {
                    return baseQuery.data;

                }
            }),

        }
    }
});


//导出钩子函数给外部使用，自动生成hooks的名称为`use(Endpoint_name)Query`
export const { usePostloginMutation, usePostlogoutMutation } = loginApi;